package po;

import java.io.Serializable;
import java.util.ArrayList;

import appendix.Period;
import appendix.Time;

public class CoursePO implements Serializable{

	private long id = 0;
	private int credit = 0;
	private String name = null;
	private Time time = null;
	private String place = null;
	private long teacherID = 0;
	private String classHour = null;
	private String intros = null;
	private String books = null;
	private String partment = null;
	private boolean isCompulsory = false;
	private boolean isExamined = true;
	private int studentNum = 0;

	public CoursePO(long id, int credit, String name, Time time,
			String place, long teacherID, String classHour, String intros,
			String books, String partment, boolean isCompulsory, boolean isExamined, int studentNum) {
		this.id = id;
		this.credit = credit;
		this.name = name;
		this.time = time;
		this.place = place;
		this.teacherID = teacherID;
		this.classHour = classHour;
		this.intros = intros;
		this.books = books;
		this.partment = partment;
		this.isCompulsory = isCompulsory;
		this.isExamined = isExamined;
		this.studentNum = studentNum;
	}

	public long getID() {
		return id;
	}

	public void setID(long newID) {
		id = newID;
	}

	public int getCredit() {
		return credit;
	}

	public void setCredit(int newCredit) {
		credit = newCredit;
	}

	public String getName() {
		return name;
	}

	public void setName(String newName) {
		name = newName;
	}

	public Time getTime() {
		return time;
	}

	public void setTime(Time newTime) {
		time = newTime;
	}

	public String getPlace() {
		return place;
	}

	public void setPlace(String newPlace) {
		place = newPlace;
	}

	public long getTeacherID() {
		return teacherID;
	}

	public void setTeacherID(long newTeacherID) {
		teacherID = newTeacherID;
	}

	public String getClassHour() {
		return classHour;
	}

	public void setClassHour(String newClassHour) {
		classHour = newClassHour;
	}

	public String getIntros() {
		return intros;
	}

	public void setIntros(String newIntros) {
		intros = newIntros;
	}

	public String getBooks() {
		return books;
	}

	public void setBooks(String newBooks) {
		books = newBooks;
	}

	public String getPartment() {
		return partment;
	}

	public void setPartment(String newPartment) {
		partment = newPartment;
	}

	public boolean isCompulsory() {
		return isCompulsory;
	}

	public void setIsCompulsory(boolean newIsCompulsory) {
		isCompulsory = newIsCompulsory;
	}

	public boolean isExamined() {
		return isExamined;
	}

	public void setExamined(boolean isExamined) {
		this.isExamined = isExamined;
	}

	public int getStudentNum() {
		return studentNum;
	}

	public void setStudentNum(int studentNum) {
		this.studentNum = studentNum;
	}

	public String[] toList() {
		String[] result = new String[10];
		result[0] = id + "";
		result[1] = credit + "";
		result[2] = name;
		result[3] = time.toString();
		result[4] = place;
		result[5] = teacherID + "";
		result[6] = classHour;
		result[7] = intros;
		result[8] = books;
		result[9] = isCompulsory + "";
		return result;
	}

	public boolean equals(Object obj) {
		CoursePO course = (CoursePO) obj;
		if (id == course.getID()) {
			return true;
		} else {
			return false;
		}
	}

	public boolean isConflict(CoursePO another) {
		if (another.getPlace().equals(place)) {
			if (another.getTime().isConflict(time)) {
				return true;
			}
		}
		return false;
	}

	public static void main(String[] arg) {
		ArrayList<Period> alist = new ArrayList<Period>();
		for ( int i = 1; i < 8; i++) {
			for (int j = 1; j < 4; j++) {
				Period as = new Period(i,j);
				alist.add(as);
			}
		}
		ArrayList<Period> blist = new ArrayList<Period>();
		for ( int i = 1; i < 2; i++) {
			for (int j = 3; j < 4; j++) {
				Period as = new Period(i,j);
				blist.add(as);
			}
		}
		Time a1 = new Time(alist);
		Time b1 = new Time(blist);

		CoursePO a = new CoursePO(0, 0, null, a1, "a", 7, null, null, null, null, false, false, 0);
		CoursePO b = new CoursePO(0, 0, null, b1, "a", 7, null, null, null, null, false, false, 0);
		System.out.println(a.isConflict(b));
		System.out.println(a1.toString());
		System.out.println(b1.toString());
	}
}
